<template>
  <view class="template-shop tn-safe-area-inset-bottom">
    <!-- 顶部自定义导航 -->
    <tn-nav-bar fixed customBack :bottomShadow="false" backgroundColor="#FFFFFF">
      <view slot="back" class='tn-custom-nav-bar__back' @click="goBack">
        <text class='icon tn-icon-left-arrow'></text>
      </view>
      <view class="tn-flex tn-flex-col-center tn-flex-row-center">
        <text class="tn-text-bold tn-text-xl tn-color-black">闲置房间</text>
      </view> 
    </tn-nav-bar>

    <view class="" :style="{paddingTop: vuex_custom_bar_height + 10 + 'px'}">
      
      <!-- 搜索框 -->
      <view class="tn-search-bar" style="width: 94%;margin-left: 3%;">
        <tn-input class="tn-input" border borderColor="#01BEFF" type="text" v-model="searchQuery" placeholder="请输入房间号搜索" />
      </view>

      <!-- 商品 start-->
      <view class="tn-flex tn-flex-wrap" style="margin: 10rpx 14rpx 0 14rpx;">
        <block v-for="(item, index) in filteredRooms" :key="index">
          <view class="" style="width: 50%;" @click="details(item)">
            <view class="shop-shadow" style="margin: 0 16rpx 30rpx 16rpx;">
              <view class="image-pic" :style="'background-image:url(' + (item.photo ? item.photo : otherImage) + ')'">
                <view class="image-product"></view>
              </view>
              <view class="tn-text-justify tn-padding-top-sm tn-padding-bottom-xs clamp-text-1 tn-text-bold" style="color: #333333;max-height: 60rpx;">
                <text class="tn-padding-left-sm tn-padding-right-sm">{{ item.roomNumber }}</text>  
              </view>
              <view class="tn-flex tn-flex-row-between tn-flex-col-center tn-padding-bottom-sm tn-padding-top-sm">
                <view class="justify-content-item tn-flex tn-flex-col-center tn-padding-left-sm tn-padding-right-sm" style="margin-left: -6rpx;color: #333333;">
                  <text class="tn-text-sm">￥</text>
                  <text class="tn-padding-right-sm tn-text-lg tn-text-bold tn-color-orangeyellow">{{ item.rent }}</text>
                  <text class="tn-color-gray tn-text-sm" style="color: #C1CACF;">{{ item.propertyName }}</text>
                </view>
              </view>
            </view>
          </view>
        </block>
      </view>
      <!-- 商品 end-->
    </view>
    
    <view class="tn-tabbar-height"></view>
    
  </view>
</template>

<script>
  import { getIdleList } from '@/api/house/room/index';

  export default {
    name: 'Shop',
    data() {
      return {
        product: [],       // List of rooms
        searchQuery: '',   // Search query for filtering rooms
        otherImage: '/static/images/room/SpareRoom.png'
      };
    },
    created() {
      this.IdleList();
    },
    computed: {
      filteredRooms() {
        if (this.searchQuery) {
          // Filter rooms by roomNumber based on the searchQuery
          return this.product.filter(item => item.roomNumber.includes(this.searchQuery));
        }
        return this.product;
      }
    },
    methods: {
      IdleList() {
        getIdleList().then(response => {
          console.log("response", response);
          this.product = response.data;
        });
      },
      details(res) {
        console.log(res);
        uni.navigateTo({
          url: 'details?res=' + encodeURIComponent(JSON.stringify(res))
        });
      },
      goBack() {
        uni.navigateBack({
          delta: 1 // Return to the previous page
        });
      },
    }
  };
</script>


<style lang="scss" scoped>
	
	/* 胶囊*/
	.tn-custom-nav-bar__back {
		width: 60%;
		height: 100%;
		position: relative;
		display: flex;
		justify-content: space-evenly;
		align-items: center;
		box-sizing: border-box;
		background-color: rgba(0, 0, 0, 0.15);
		border-radius: 1000rpx;
		border: 1rpx solid rgba(255, 255, 255, 0.5);
		color: #FFFFFF;
		font-size: 18px;
	
		.icon {
			display: block;
			flex: 1;
			margin: auto;
			text-align: center;
		}
	}
  .template-shop{
    max-height: 94vh;
    max-height: calc(94vh + env(safe-area-inset-bottom) / 2);
    max-height: calc(94vh + constant(safe-area-inset-bottom));
  }
  /* 自定义导航栏内容 start */
  .custom-nav {
    height: 100%;
  
    &__logo {
      margin: auto 5rpx;
      font-size: 50rpx;
      margin-right: 10rpx;
      margin-left: 30rpx;
      flex-basis: 5%;
    }
  }
  /* 自定义导航栏内容 end */
  .bg-radius{
    background-color: #FFFFFF;
    border-radius: 16rpx;
    margin: 30rpx;
    padding: 30rpx;
  }
  
  .shop-shadow{
    background-color: #FFFFFF;
    border-radius: 24rpx;
  }
  
  .image-product{
    padding: 145rpx 0rpx;
    font-size: 16rpx;
    font-weight: 300;
    position: relative;
  }
  .image-pic{
    background-size: cover;
    background-repeat:no-repeat;
    // background-attachment:fixed;
    background-position:center;
    border-radius: 24rpx;
    border: 10rpx solid #FFFFFF;;
  }
  
  /* 底部安全边距 start*/
  .tn-tabbar-height {
    min-height: 100rpx;
    height: calc(120rpx + env(safe-area-inset-bottom) / 2);
    height: calc(120rpx + constant(safe-area-inset-bottom));
  }
  
  /* 文字截取*/
  .clamp-text-1 {
    -webkit-line-clamp: 1;
    display: -webkit-box;
    -webkit-box-orient: vertical;
    text-overflow: ellipsis;
    overflow: hidden;
  }
  
  .clamp-text-2 {
    -webkit-line-clamp: 2;
    display: -webkit-box;
    -webkit-box-orient: vertical;
    text-overflow: ellipsis;
    overflow: hidden;
  }
  
</style>
